package servlet;

import java.io.IOException;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import pojo.Order;
import pojo.User;

public class AddToCartServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public AddToCartServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String bid = (String) request.getParameter("id");
		System.out.println(bid);
		HttpSession session = request.getSession();
		Map<String, Integer> bNum = (Map<String, Integer>) session.getAttribute("bnum");
		for(String s:bNum.keySet()){
			System.out.println(bNum.get(s));
		}
		int count = bNum.get(bid).intValue();
		System.out.println("add to cart: "+count);
		bNum.put(bid, (count+1));
		session.setAttribute("bnum", bNum);
		response.sendRedirect("../home.jsp");
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
